package com.G_CN06.mvc.controller.F10.F101;

import com.G_CN06.commonUtil.commonResultConfig.CommonResult;
import com.G_CN06.mvc.entity.*;
import com.G_CN06.mvc.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hcx
 * @className F1021QuestionListController
 * @description 题库展示
 * @since 2023/2/10 10:18
 **/
@RestController
@CrossOrigin
@RequestMapping("/question-list")
public class F1012QuestionListController {
    @Autowired
    FillQuestionService fillQuestionService;
    @Autowired
    ChoiceQuestionService choiceQuestionService;
    @Autowired
    MultiChoiceQuestionService multiChoiceQuestionService;
    @Autowired
    JudgeQuestionService judgeQuestionService;
    @Autowired
    SubjectivityQuestionService subjectivityQuestionService;

    @GetMapping("/getAllChoiceQuestion")
    public CommonResult getAllChoiceQuestion(){
        CommonResult r = new CommonResult();
        List<ChoiceQuestion> list = choiceQuestionService.list(null);
        r.ok("list",list);
        return r;
    }


    @GetMapping("/getConditionalChoiceQuestion")
    public CommonResult getConditionalChoiceQuestion(String searchString){
        return choiceQuestionService.getConditionalQuestion(searchString);
    }

    @GetMapping("/getAllFillQuestion")
    public CommonResult getAllFillQuestion(){
        CommonResult r = new CommonResult();
        List<FillQuestion> list = fillQuestionService.list(null);
        r.ok("list",list);
        return r;
    }


    @GetMapping("/getConditionalFillQuestion")
    public CommonResult getConditionalFillQuestion(String searchString){
        return fillQuestionService.getConditionalQuestion(searchString);
    }

    @GetMapping("/getAllSubjectivityQuestion")
    public CommonResult getAllSubjectivityQuestion(){
        CommonResult r = new CommonResult();
        List<SubjectivityQuestion> list = subjectivityQuestionService.list(null);
        r.ok("list",list);
        return r;
    }


    @GetMapping("/getConditionalSubjectivityQuestion")
    public CommonResult getConditionalSubjectivityQuestion(String searchString){
        return subjectivityQuestionService.getConditionalQuestion(searchString);
    }

    @GetMapping("/getAllMultiChoiceQuestion")
    public CommonResult getAllMultiChoiceQuestion(){
        CommonResult r = new CommonResult();
        List<MultiChoiceQuestion> list = multiChoiceQuestionService.list(null);
        r.ok("list",list);
        return r;
    }


    @GetMapping("/getConditionalMultiChoiceQuestion")
    public CommonResult getConditionalMultiChoiceQuestion(String searchString){
        return multiChoiceQuestionService.getConditionalQuestion(searchString);
    }

    @GetMapping("/getAllJudgeQuestion")
    public CommonResult getAllJudgeQuestion(){
        CommonResult r = new CommonResult();
        List<JudgeQuestion> list = judgeQuestionService.list(null);
        r.ok("list",list);
        return r;
    }


    @GetMapping("/getConditionalJudgeQuestion")
    public CommonResult getConditionalJudgeQuestion(String searchString){
        return judgeQuestionService.getConditionalQuestion(searchString);
    }

    @DeleteMapping("/deleteFillQuestion")
    public CommonResult deleteFillQuestion(Integer id){
        return fillQuestionService.removeById(id)?new CommonResult().ok():new CommonResult().error();
    }

    @DeleteMapping("/deleteMultiChoiceQuestion")
    public CommonResult deleteMultiChoiceQuestion(Integer id){
        return multiChoiceQuestionService.removeById(id)?new CommonResult().ok():new CommonResult().error();
    }

    @DeleteMapping("/deleteJudgeQuestion")
    public CommonResult deleteJudgeQuestion(Integer id){
        return judgeQuestionService.removeById(id)?new CommonResult().ok():new CommonResult().error();
    }

    @DeleteMapping("/deleteSubjectivityQuestion")
    public CommonResult deleteSubjectivityQuestion(Integer id){
        return subjectivityQuestionService.removeById(id)?new CommonResult().ok():new CommonResult().error();
    }

    @DeleteMapping("/deleteChoiceQuestion")
    public CommonResult deleteChoiceQuestion(Integer id){
        return choiceQuestionService.removeById(id)?new CommonResult().ok():new CommonResult().error();
    }

    @PostMapping("/updateChoiceQuestion")
    public CommonResult updateChoiceQuestion(@RequestBody ChoiceQuestion choiceQuestion){
        return choiceQuestionService.updateById(choiceQuestion)?new CommonResult().ok():new CommonResult().error();
    }

    @PostMapping("/updateFillQuestion")
    public CommonResult updateFillQuestion(@RequestBody FillQuestion fillQuestion){
        return fillQuestionService.updateById(fillQuestion)?new CommonResult().ok():new CommonResult().error();
    }

    @PostMapping("/updateMultiChoiceQuestion")
    public CommonResult updateMultiChoiceQuestion(@RequestBody MultiChoiceQuestion multiChoiceQuestion){
        return multiChoiceQuestionService.updateById(multiChoiceQuestion)?new CommonResult().ok():new CommonResult().error();
    }

    @PostMapping("/updateJudgeQuestion")
    public CommonResult updateJudgeQuestion(@RequestBody JudgeQuestion judgeQuestion){
        return judgeQuestionService.updateById(judgeQuestion)?new CommonResult().ok():new CommonResult().error();
    }

    @PostMapping("/updateSubjectivityQuestion")
    public CommonResult updateSubjectivityQuestion(@RequestBody SubjectivityQuestion subjectivityQuestion){
        return subjectivityQuestionService.updateById(subjectivityQuestion)?new CommonResult().ok():new CommonResult().error();
    }

}
